<?php
$sysApps = new sysApps();
$sysApps->DBconnect();
?>

<div class="page-info">
	<div class="pageTitle">Submission List</div>
    <div class="user_email bgGrey">Email</div>
    <div class="user_MGM_id bgGrey">MGM ID</div>
    <div class="user_start_date bgGrey">Start Month</div>
    <div class="user_end_date bgGrey">End Month</div>
    <div class="clearFloat"></div>
    
    
    <?php
		$user_id = $_SESSION['login_id'];
		$sql = "SELECT mu.id, mu.email, mu.user_MGM_id, us.start_month, us.end_month
		FROM mgm_users mu
		LEFT JOIN user_subscription us 
		ON mu.id = us.user_id
		WHERE mu.sponsor_id = '".$user_id."'
		AND (us.end_month = (SELECT MAX(us1.end_month) 
							FROM user_subscription us1
							WHERE us1.user_id = mu.id)
	   		OR us.end_month IS NULL )
		GROUP BY mu.id 
		ORDER BY mu.id ";
			
		$query = mysql_query($sql);
		while ($row = mysql_fetch_array($query)) {
			//echo '<p>'.$row['id'].'+'.$row['email'].'+'.$row['user_MGM_id'].'+'.$row['fullname'].'+'.$row['start_month'].'+'.$row['end_month'].'</p>';
			echo '<div class="user_email">'.$row['email'].'</div>';
			echo '<div class="user_MGM_id">'.$row['user_MGM_id'].'</div>';
			echo '<div class="user_start_date">'.$row['start_month'].'</div>';
			echo '<div class="user_end_date">'.$row['end_month'].'</div>';
			echo '<div class="clearFloat"></div>';
		}
	?>
</div>